#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
# $Id: configure.ac 103 2008-04-09 07:03:06Z dubkat $

AC_INIT([pidgin-woodpecker],[0.0.1],[http://code.google.com/p/pidgin-woodpecker])
AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)

AC_PREREQ([2.50])

REQUIRED_PKG_CONFIG="0.15.0"
AC_SUBST(REQUIRED_PKG_CONFIG)

REQUIRED_PURPLE="purple purple >= 2.0"
AC_SUBST(REQUIRED_PURPLE)
REQUIRED_PIDGIN="pidgin pidgin >= 2.0"
AC_SUBST(REQUIRED_PIDGIN)

REQUIRED_GTK="gtk+-2.0"
AC_SUBST(REQUIRED_GTK)

AC_CONFIG_SRCDIR([common/pecker.h])


# Checks for programs.
AC_PROG_CC
AC_DISABLE_STATIC
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
LIBTOOL="$LIBTOOL --silent"
AC_PROG_INSTALL
AC_PATH_PROG(PKG_CONFIG, [pkg-config], [no])

if test x$PKG_CONFIG = xno ; then
  AC_MSG_ERROR([*** pkg-config not found])
fi

# Build preferences

AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],
 [compile with debugging support])], , enable_debug=no)

if test "x$enable_debug" = "xyes" ; then
  AC_DEFINE(DEBUG, 1, [Define if debugging is enabled.])
fi


AC_ARG_ENABLE([pecker],
	[AS_HELP_STRING(--enable-pecker,build the woodpecker plugin @<:@default=yes@:>@)],,
	[enable_pecker="yes"])

AC_ARG_ENABLE([extras],
	[AS_HELP_STRING(--enable-extras,build the extras plugin @<:@default=no@:>@)],,
	[enable_extras="no"])

#AC_ARG_ENABLE([display-options],
# [AS_HELP_STRING(--enable-display-options, include display options @<:@default=no@:>@)],,
#		[enable_display_options="no"])

AM_CONDITIONAL([COND_DISPLAY_OPTIONS], [test "$enable_display_options" = "yes"])
AM_CONDITIONAL([COND_PECKER], [test "$enable_pecker" = "yes"])
AM_CONDITIONAL([COND_PECKER_EXTRAS], [test "$enable_extras" = "yes"])

if test "$enable_display_options" != "yes" ; then
	enable_display_options="no"
fi
if test "$enable_pecker" != "yes" ; then
	enable_pecker="no"
fi

if test "$enable_extras" != "yes" ; then
	enable_extras="no"
## force disable of broken extras
#else
# echo "***** WARNING *****"
# echo "WoodPecker Extras is currently broken, and forcibly disabled"
# echo "until it is fixed enough to be usable."
# echo "***** WARNING *****"
# enable_extras="no"
fi

# Checks for libraries.
AC_ARG_WITH([purple-prefix],
	[AS_HELP_STRING(--with-purple-prefix,specify the prefix where Pidgin is found)],
	PKG_CONFIG_PATH=$withval/lib/pkgconfig,[])
export PKG_CONFIG_PATH

PKG_PROG_PKG_CONFIG([$REQUIRED_PKG_CONFIG])
if test "$enable_extras" = "yes" ; then
	PKG_CHECK_MODULES([GTK], [$REQUIRED_GTK],
		[
		AC_SUBST(GTK_CFLAGS)
		AC_SUBST(GTK_LIBS)
		]
	)
fi
PKG_CHECK_MODULES([PURPLE], [$REQUIRED_PURPLE],
	[
	AC_SUBST(PURPLE_CFLAGS)
	AC_SUBST(PURPLE_LIBS)
	]
)
PKG_CHECK_MODULES([PIDGIN], [$REQUIRED_PIDGIN],
 [
		AC_SUBST(PIDGIN_CFLAGS)
		AC_SUBST(PIDGIN_LIBS)
 ]
)

AC_ARG_VAR([PURPLE_DATADIR], [datadir of PURPLE, overriding pkg-config])dnl
AC_ARG_VAR([PURPLE_LIBDIR], [libdir of PURPLE, overriding pkg-config])dnl
AC_CACHE_CHECK([for PURPLE][_DATADIR], [pkg_cv_][PURPLE][_DATADIR],
	[_PKG_CONFIG([PURPLE][_DATADIR], [variable=datadir], [purple])])
AC_CACHE_CHECK([for PURPLE][_LIBDIR], [pkg_cv_][PURPLE][_LIBDIR],
	[_PKG_CONFIG([PURPLE][_LIBDIR], [variable=libdir], [purple])])
PURPLE[]_DATADIR=$pkg_cv_[]PURPLE[]_DATADIR
PURPLE[]_LIBDIR=$pkg_cv_[]PURPLE[]_LIBDIR
AC_SUBST(PURPLE_DATADIR)
AC_SUBST(PURPLE_LIBDIR)

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h string.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T

# Checks for library functions.
AC_CHECK_FUNCS([gethostname inet_ntoa memmove strcasecmp strchr strdup strerror strpbrk strrchr strstr strtoul])

case "$host" in
	*-*-mingw*)
	CFLAGS="$CFLAGS -O2 -Wall -mno-cygwin -mms-bitfields"
	LIBS="$LIBS -no-undefined -Wl,--enable-auto-image-base -lws2_32"
	;;
	*)
	;;
esac

if test "x$GCC" = "xyes"; then
	CFLAGS="$CFLAGS"
	if test "$enable_debug" = "yes"; then
    CFLAGS="$CFLAGS -O0 -g -g3 -ggdb -Wall"
	fi
fi
AC_SUBST(CFLAGS)


AC_CONFIG_FILES([Makefile
                 woodpecker/Makefile
                 woodpecker/pixmaps/Makefile
                 woodpecker/pixmaps/16/Makefile
                 woodpecker/pixmaps/22/Makefile
                 woodpecker/pixmaps/48/Makefile
                 woodpecker/src/Makefile
                 extras/Makefile
                 extras/src/Makefile
                 extras/pixmaps/Makefile
                 nsis/Makefile
																	nsis/locale/Makefile])

AC_OUTPUT

echo
echo "                         _                 _             "
echo "__      _____   ___   __| |_ __   ___  ___| | _____ _ __ "
echo "\ \ /\ / / _ \ / _ \ / _\` | '_ \ / _ \/ __| |/ / _ \ '__|"
echo " \ V  V / (_) | (_) | (_| | |_) |  __/ (__|   <  __/ |   "
echo "  \_/\_/ \___/ \___/ \__,_| .__/ \___|\___|_|\_\___|_|   "
echo "                          |_|  $PACKAGE $VERSION "
echo

echo
echo Build gay.com \(pecker\) plugin..... : $enable_pecker
echo Build gay.com extras plugin....... : $enable_extras
echo
echo Build with debugging enabled...... : $enable_debug
echo
echo Installation directory............ : $PURPLE_LIBDIR/purple-2
echo
echo PECKER_CFLAGS: $CFLAGS
echo PURPLE_CFLAGS: $PURPLE_CFLAGS
echo PIDGIN_CFLAGS: $PIDGIN_CFLAGS
echo
echo configure complete, now type \'make\'
echo

